home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / C005.ZIP / FLOOR.C < prev    next >
Text File  |  1990-01-19  |  1KB  |  42 lines

  1. /********************************************************************
  2.  * C Users Group (U.K) C Source Code Library File CUGLIB.005        *
  3.  * Inquiries to: M. Houston, 36 Whetstone Clo. Farquhar Rd.         *
  4.  * Edgbaston, Birmingham B15 2QN ENGLAND                *
  5.  ********************************************************************
  6.  * File name: floor.c
  7.  * Program name: library modules only
  8.  * Source of file: The Public Domain Software Library.
  9.  * Purpose: maths function
  10.  * Changes: <who what when & why major changes have been made>      
  11.  ********************************************************************/
  12.  
  13.  
  14. /***********************************************************
  15.  *               The TULSA IBM C BOARD                     *
  16.  *                   918-664-8737                          *
  17.  *             300/1200 XMODEM, 24 Hours                   *
  18.  **********************************************************/
  19.  
  20.  
  21. #include "math.h"
  22.  
  23. double floor(d)
  24. double d;
  25. {
  26.         if (d < 0.0)
  27.                 return -ceil(-d);
  28.         modf(d, &d);
  29.         return d;
  30. }
  31.  
  32. double ceil(d)
  33. double d;
  34. {
  35.         if (d < 0.0)
  36.                 return -floor(-d);
  37.         if (modf(d, &d) > 0.0)
  38.                 ++d;
  39.         return d;
  40. }
  41.  
  42.